 jQuery(function() {
	 jQuery("#source").val(jQuery("#source1").val());
	 jQuery("#sourceType").val(jQuery("#sourceType1").val());
	 jQuery("#sourcePower").val(jQuery("#sourcePower1").val());
	 jQuery("#orderUnitArea").val(jQuery("#orderUnitArea1").val());
	    
	 var serverData1 = {};
	 var serverTable1;
	    jQuery(document).ready(function () {
	    	serverTable1 = jQuery('#keyManTable').DataTable({
		        "serverSide": true,
		        "ordering": false,
		        "ajax": {
		            "dataType": "json",
		            "type": "get",
		            "cache": false,
		            "url":window.rootPath+ '/ui/chanceKeyMan/getpage'+"?chanceId="+$("#id").val(),
		            "data": function (d) {
		                return $.extend({}, d, serverData1);
		            }
		        },
		        "iDisplayLength": 5,
		        columns: [
		            {
		            data: null
		            },
		            {
		                data: 'keyManName'
		            },
		            {
		                data: 'business'
		            },
		            {
		                data: 'phone'
		            },
		            {
		                data: 'callName',
		                
		            },
		            {
		                data: 'keyMemo',
		                
		            } 
		          ],
		        "drawCallback": function (oSettings) {
		            var k = 0;
		            var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

		            for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
		                $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
		                k++;
		            }

		            serverTable1.off('click', 'tr');
		            serverTable1.on('click', 'tr', function (event) {
		                event = event || window.event;
		                var target = event.target || event.scrElement;
		                var data = serverTable.row(this).data();

		                return;
		            });
		        }
		    });
	    	});
		 var serverData2 = {};
		 var serverTable2;
		    jQuery(document).ready(function () {
		    	serverTable2 = jQuery('#allTranceTable').DataTable({
			        "serverSide": true,
			        "ordering": false,
			        "ajax": {
			            "dataType": "json",
			            "type": "get",
			            "cache": false,
			            "url":window.rootPath+ '/ui/chanceTrance/getAllTrance'+"?chanceId="+$("#id").val(),
			            "data": function (d) {
			                return $.extend({}, d, serverData2);
			            }
			        },
			        "iDisplayLength": 5,
			        columns: [
			            {
   	            	
   	                   data: 'createTime',
            	       render : function(data,type, full,meta) {
						       if (data) 
						      {
							      return moment(data).format("YYYY-MM-DD");
						      }
            	            }
   		         },
   	            {
   	                data: 'user.empLogin.userName'
   	            },
   	            {
   	            	data: null,
   	                defaultContent: "",
   	                render: function (data, type, full, meta) {
   	                	var text;
   	                		text ='<p>'+data.user.saleArea.superior+"-"+data.user.saleArea.areaName+'</p>';
   	                    
   	                    return text;

   	                }
   	            },
   	            {
   	                data: 'tranceInfo',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 8) ? '<font title="'+data+'">'+data.substring(0,8)+'...'+'</font>' : data;
						}
					}
   	                
   	            },
   	            {
   	                data: 'tranceResult',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 20) ? '<font title="'+data+'">'+data.substring(0,20)+'...'+'</font>' : data;
						}
					}
   	                
   	            },
   	            {
   	                data: 'orderAmount',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 15) ? '<font title="'+data+'">'+data.substring(0,15)+'...'+'</font>' : data;
						}
					}
   	                
   	            }
			          ],
			        "drawCallback": function (oSettings) {
			            var k = 0;
			            var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;


			            serverTable2.off('click', 'tr');
			            serverTable2.on('click', 'tr', function (event) {
			                event = event || window.event;
			                var target = event.target || event.scrElement;
			                var data = serverTable.row(this).data();

			                return;
			            });
			        }
			    });
		    	});
 });